package com.engine.budget.manager;

import com.engine.budget.enums.Instruction;
import com.engine.budget.enums.VerifyMessage;
import com.engine.budget.util.VerifyUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.TimeUtil;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.integration.logging.Logger;
import weaver.integration.logging.LoggerFactory;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;

/**
 * @author DY
 * @version 1.0
 * @date 2024/7/9 13:57
 * @description: 执行预算指令工具类，数据入库
 */
public class InstructionManager {

    private Map<String, Object> otherParams;

    private String logId;

    //执行指令参数
    private Map<String, Object> params;
    //数据库连接工具
    private RecordSetTrans rstrans;

    //事项底表
    private String yssxdbName = "uf_yssxdb";

    //项目底表
    private String ysxmdbName = "uf_ysxmdb";

    //预算占用表
    private String yszybName = "uf_yszyb";


    private Logger logger = LoggerFactory.getLogger(this.getClass());


    /**
     * @param: allparams
     * otherMap
     * @return: java.util.Map<java.lang.String, java.lang.Object>
     * @description: 执行预算指令
     */
    public Map<String, Object> execBudget(Map<String, Object> allparams, Map<String, Object> otherMap) {
        //返回数据
        Map<String, Object> result = new HashMap();
        RecordSetTrans rsTrans = new RecordSetTrans();
        try {
            this.logId = Util.null2String(otherMap.get("logId"));
            result.put("logId", logId);
            logger.info("调用预算执行指令接口cmd_start...LogID:" + logId);

            //业务参数
            JSONArray paramsArr = JSONArray.fromObject(allparams.get("params"));
            //返回数据数组
            JSONArray resArray = new JSONArray();
            //验证失败的表示
            boolean errFlag = false;

            RecordSet rs = new RecordSet();

            String sql = "select sfxrdb from uf_djkzclb where zhdjh = ?";

            for (int i = 0; i < paramsArr.size(); i++) {

                JSONObject data = paramsArr.getJSONObject(i);

                //执行单据号
                String exeDocNo = Util.null2String(data.getOrDefault("exeDocNo", ""));
                rs.executeQuery(sql, exeDocNo);
                if (rs.next()) {
                    otherMap.put("whiteZxdjh", "1");
                } else {
                    otherMap.put("whiteZxdjh", "0");
                }

                Map<String, Object> checkMap = VerifyUtil.verifyParams(data, otherMap, rs);
                otherMap.remove("whiteZxdjh");
                String status = Util.null2String(checkMap.getOrDefault("status", ""));
                if (!"1".equals(status) && !"-11".equals(status)) {
                    errFlag = true;
                }
                resArray.add(checkMap);
            }

            if (errFlag) {
                result.put("result", resArray);
                return result;
            }

            InstructionManager instructionManager = new InstructionManager();

            JSONArray newResArray = new JSONArray();

            for (int i = 0; i < paramsArr.size(); i++) {

                JSONObject data = paramsArr.getJSONObject(i);

                //执行单据号
                String exeDocNo = Util.null2String(data.getOrDefault("exeDocNo", ""));
                //是否写入数据
                String sfxrdb = "";
                rs.executeQuery(sql, exeDocNo);
                if (rs.next()) {
                    sfxrdb = Util.null2String(rs.getString("sfxrdb"));
                }


                JSONObject yzData = resArray.getJSONObject(i);

                String status = Util.null2String(yzData.getOrDefault("status", ""));
                if (!"-11".equals(status) && !"1".equals(sfxrdb)) {
                    Map<String, Object> resMap = instructionManager.execute(data, otherMap, rsTrans);
                    JSONObject resdata = yzData.getJSONObject("data");
                    resMap.put("data", resdata);
                    yzData = JSONObject.fromObject(resMap);
                }
                newResArray.add(yzData);

                InstructionManager.addInstructionLog(data, yzData, rs);

            }
            rsTrans.commit();

            result.put("result", newResArray);
        } catch (Exception e) {

        }
        return result;
    }

    /**
     * @param:
     * @return: java.util.Map<java.lang.String, java.lang.Object>
     * @description: 执行预算常规指令
     */
    public Map<String, Object> execute(Map<String, Object> params, Map<String, Object> otherParams,
                                       RecordSetTrans rstrans) {

        this.params = params;
        this.otherParams = otherParams;
        this.logId = Util.null2String(otherParams.getOrDefault("logId", logId));
        this.rstrans = rstrans;


        //执行指令
        String instruction = Util.null2String(params.getOrDefault("instruction", ""));
        boolean b = Instruction.hasInstance(instruction);

        if (!b) {
            Map<String, Object> errMap = VerifyMessage.YSZL_ERR.fromMap();
            errMap.put("status", -2);

            return errMap;
        }

        //电商平台控制接口 查询年度剩余可用预算百分比接口单独处理
        if (Instruction.IA.equals(instruction)) {
            Map<String, Object> resMap = getRemainBudgetPer();
            return resMap;
        }

        //金额字段写入年度预算明细表
        Map<String, Object> resMap = writeInNdysmx();
        String status = Util.null2String(resMap.get("status").toString());
        if (!"0".equals(status)) {
            return resMap;
        }

        //金额字段写入全周期预算明细表
        resMap = writeInQzqysmx();
        status = Util.null2String(resMap.get("status").toString());
        if (!"0".equals(status)) {
            return resMap;
        }

        //新插入的占用表id
        List<String> modeids = new ArrayList<>();
        //金额字段写入占用明细表
        resMap = writeInZybmx(modeids);
        status = Util.null2String(resMap.get("status").toString());
        if (!"0".equals(status)) {
            return resMap;
        }

        try {
            if (modeids.size() > 0) {
                ModeRightInfo moderight = new ModeRightInfo();
                String sql = "select a.id modeid from modeinfo a left join workflow_bill b on a.formid=b.id where b.tablename= ? ";
                rstrans.executeQuery(sql, yszybName);
                rstrans.next();
                int modeid = Util.getIntValue(rstrans.getString("modeid"), -1);

                User user = (User) otherParams.get("user");
                int userid = user.getUID();

                for (String dataid : modeids) {
                    moderight.rebuildModeDataShareByEdit(userid, modeid, Util.getIntValue(dataid));
                }
            }
        } catch (Exception e) {
            logger.info("logId:" + logId + "预算占用表新增主表数据权限重构失败，err:" + e.getMessage(), e);
        }

        return resMap;
    }

    /**
     * @param:
     * @return: java.util.Map<java.lang.String, java.lang.Object>
     * @description: 金额字段写入年度预算明细表
     */
    public Map<String, Object> writeInNdysmx() {

        Map<String, Object> resMap = new HashMap<>();

        //执行数 字段名
        String zhsname = "zhs";
        //占用数 字段名
        String zysname = "zys";

        //       预算指令	              执行数	         占用数
//        执行           ZX	     累加【传入金额】
//        释放执行        SFZX	 累减【传入金额】
//        占用	        ZY	                    累加【传入金额】
//        释放占用       SFZY	                    累减【传入金额】
//        释放占用且执行  SFZYQZX   累加【传入金额】	累减【传入金额】
//        释放执行且占用  SFZXQZY   累减【传入金额】	累加【传入金额】
        Map<String, Map<String, Integer>> insRulMap = new HashMap<>();
        //执行
        Map<String, Integer> zxMap = new HashMap<>();
        zxMap.put(zhsname, 1);
        zxMap.put(zysname, 0);
        insRulMap.put(Instruction.ZX.getValue(), zxMap);

        //释放执行
        Map<String, Integer> sfzxMap = new HashMap<>();
        sfzxMap.put(zhsname, -1);
        sfzxMap.put(zysname, 0);
        insRulMap.put(Instruction.SFZX.getValue(), sfzxMap);

        //占用
        Map<String, Integer> zyMap = new HashMap<>();
        zyMap.put(zhsname, 0);
        zyMap.put(zysname, 1);
        insRulMap.put(Instruction.ZY.getValue(), zyMap);

        //释放占用
        Map<String, Integer> sfzyMap = new HashMap<>();
        sfzyMap.put(zhsname, 0);
        sfzyMap.put(zysname, -1);
        insRulMap.put(Instruction.SFZY.getValue(), sfzyMap);

        //释放占用且执行
        Map<String, Integer> sfzyqzxMap = new HashMap<>();
        sfzyqzxMap.put(zhsname, 1);
        sfzyqzxMap.put(zysname, -1);
        insRulMap.put(Instruction.SFZYQZX.getValue(), sfzyqzxMap);

        //释放执行且占用
        Map<String, Integer> sfzxqzyMap = new HashMap<>();
        sfzxqzyMap.put(zhsname, -1);
        sfzxqzyMap.put(zysname, 1);
        insRulMap.put(Instruction.SFZXQZY.getValue(), sfzxqzyMap);

        try {
            //指令
            String instruction = Util.null2String(params.getOrDefault("instruction", ""));
            if (!insRulMap.containsKey(instruction)) {
                resMap.put("status", 0);
                VerifyMessage.SUCCESS.fromMap(resMap);
                return resMap;
            }

            Map<String, Integer> instructionMap = insRulMap.get(instruction);

            //预算项目
            String budgetItem = Util.null2String(params.getOrDefault("budgetItem", ""));
            //预算科目
            String budgetAccount = Util.null2String(params.getOrDefault("budgetAccount", ""));
            //执行单位
            String exeUnit = Util.null2String(params.getOrDefault("exeUnit", ""));
            //预算期间（年）
            String budgetPeriod = Util.null2String(params.getOrDefault("budgetPeriod", ""));

            //金额
            double amount = Util.getDoubleValue(
                    params.getOrDefault("amount", "0.000000").toString(), 0.000000);

            //查询项目底表需要跟新的明细
            String selectsql = "select t1.id id, t.yssx yssx from " + ysxmdbName + " t " +
                    " inner join " + ysxmdbName + "_dt1 t1 on t.id = t1.mainid " +
                    " where t.xmbm = ? and t1.yskm = ? and t.zz = ? and t1.ysnd = ? ";

            boolean sqlFlag = rstrans.executeQuery(selectsql, budgetItem, budgetAccount, exeUnit, budgetPeriod);
            logger.info("logId:" + logId + "预算项目底表年度预算明细金额字段写入查询执行结构，flag" + sqlFlag + ",sql:" + selectsql + "==>budgetItem:" + budgetItem
                    + ",budgetAccount:" + budgetAccount + ",exeUnit:" + exeUnit + ",budgetPeriod:" + budgetPeriod);

            if (!sqlFlag || rstrans.getCounts() != 1) {
                resMap.put("status", -1);
                VerifyMessage.YWYZ_ERR.setErrorMessage("预算项目底表年度预算明细未成功匹配到数据！").fromMap(resMap);
                rstrans.rollback();
                return resMap;
            }
            rstrans.next();

            //项目底表_Dt1跟新数据id
            String xmid = rstrans.getString("id");

            //预算事项id
            String yssxid = rstrans.getString("yssx");

            //查询事项底表需要跟新的明细
            selectsql = "select t1.id id from " + yssxdbName + " t " +
                    " inner join " + yssxdbName + "_dt1 t1 on t.id = t1.mainid " +
                    " where t.sxbm = ? and t1.yskm = ? and t1.ysnd = ? ";

            sqlFlag = rstrans.executeQuery(selectsql, yssxid, budgetAccount, budgetPeriod);
            logger.info("logId:" + logId + "预算事项底表年度预算明细金额字段写入查询执行结构，flag" + sqlFlag + ",sql:" + selectsql + "==>t1.id:" + yssxid
                    + ",budgetAccount:" + budgetAccount + ",budgetPeriod:" + budgetPeriod);

            if (!sqlFlag || rstrans.getCounts() != 1) {
                rstrans.rollback();
                resMap.put("status", -1);
                VerifyMessage.YWYZ_ERR.setErrorMessage("预算事项底表年度预算明细未成功匹配到数据！").fromMap(resMap);
                return resMap;
            }
            rstrans.next();

            //项目底表_Dt1跟新数据id
            String sxid = rstrans.getString("id");

            //更新预算项目底表sql
            String sql = "update " + ysxmdbName + "_dt1 set ";

            List<Object> upDataList = new ArrayList<>();
            for (String key : instructionMap.keySet()) {
                Integer val = instructionMap.get(key);

                upDataList.add(val * amount);
                sql = sql + (key + " = (case when " + key + " is null then 0 else " + key + " end) + ?,");
            }
            sql = sql.substring(0, sql.length() - 1);
            sql = sql + " where id = ?";
            upDataList.add(xmid);

            sqlFlag = rstrans.executeUpdate(sql, upDataList);
            logger.info("logId:" + logId + "预算项目底表年度预算明细金额字段写入结果，flag" + sqlFlag + "," +
                    "sql:" + sql + "==>" + upDataList + ":" + upDataList);
            if (!sqlFlag) {
                rstrans.rollback();
                resMap.put("status", -2);
                VerifyMessage.UPDATE_ERR.setErrorMessage("预算项目底表年度预算明细更新失败！").fromMap(resMap);
                return resMap;
            }

            //更新预算事项底表sql
            sql = "update " + yssxdbName + "_dt1 set ";

            upDataList = new ArrayList<>();
            for (String key : instructionMap.keySet()) {
                Integer val = instructionMap.get(key);

                upDataList.add(val * amount);
                sql = sql + (key + " = (case when " + key + " is null then 0 else " + key + " end) + ?,");

            }
            sql = sql.substring(0, sql.length() - 1);
            sql = sql + " where id = ?";
            upDataList.add(sxid);

            sqlFlag = rstrans.executeUpdate(sql, upDataList);
            logger.info("logId:" + logId + "预算事项底表年度预算明细金额字段写入结果，flag" + sqlFlag + ",sql:" + sql + "==>" + upDataList + ":" + upDataList);
            if (!sqlFlag) {
                rstrans.rollback();
                resMap.put("status", -2);
                VerifyMessage.UPDATE_ERR.setErrorMessage("预算事项底表年度预算明细更新失败！").fromMap(resMap);
                return resMap;
            } else {
                resMap.put("status", 0);
                VerifyMessage.SUCCESS.fromMap(resMap);
                return resMap;
            }

        } catch (Exception e) {
            rstrans.rollback();
            logger.error("logId:" + logId + "预算项目、事项底表年度预算明细更新异常，err:" + e.getMessage(), e);
            resMap.put("status", -2);
            VerifyMessage.UPDATE_ERR.setErrorMessage("预算项目、事项底表年度预算明细更新异常！").fromMap(resMap);
            return resMap;
        }
    }

    /**
     * @param:
     * @return: java.util.Map<java.lang.String, java.lang.Object>
     * @description: 金额字段写入全周期预算明细表
     */
    public Map<String, Object> writeInQzqysmx() {

        Map<String, Object> resMap = new HashMap<>();

        //执行数 字段名
        String zhsname = "zhs";
        //占用数 字段名
        String zysname = "zys";

//        预算指令	                    执行数	         占用数
//        执行	            ZX          累加【传入金额】
//        释放执行	        SFZX        累减【传入金额】
//        占用		        ZY                          累加【传入金额】
//        释放占用		    SFZY                        累减【传入金额】
//        释放占用且执行	    SFZYQZX     累加【传入金额】	累减【传入金额】
//        释放执行且占用	    SFZXQZY     累减【传入金额】	累加【传入金额】
//        仅项目执行	        XMZX        累加【传入金额】
//        仅项目释放执行	    XMSFZX      累减【传入金额】
//        仅项目占用		    XMZY                        累加【传入金额】
//        仅项目释放占用		XMSFZY                      累减【传入金额】
//        仅项目释放占用且执行	XMSFZYQZX   累加【传入金额】	累减【传入金额】
//        仅项目释放执行且占用	XMSFZXQZY   累减【传入金额】	累加【传入金额】
        Map<String, Map<String, Integer>> insRulMap = new HashMap<>();
        //执行
        Map<String, Integer> zxMap = new HashMap<>();
        zxMap.put(zhsname, 1);
        zxMap.put(zysname, 0);
        insRulMap.put(Instruction.ZX.getValue(), zxMap);

        //释放执行
        Map<String, Integer> sfzxMap = new HashMap<>();
        sfzxMap.put(zhsname, -1);
        sfzxMap.put(zysname, 0);
        insRulMap.put(Instruction.SFZX.getValue(), sfzxMap);

        //占用
        Map<String, Integer> zyMap = new HashMap<>();
        zyMap.put(zhsname, 0);
        zyMap.put(zysname, 1);
        insRulMap.put(Instruction.ZY.getValue(), zyMap);

        //释放占用
        Map<String, Integer> sfzyMap = new HashMap<>();
        sfzyMap.put(zhsname, 0);
        sfzyMap.put(zysname, -1);
        insRulMap.put(Instruction.SFZY.getValue(), sfzyMap);

        //释放占用且执行
        Map<String, Integer> sfzyqzxMap = new HashMap<>();
        sfzyqzxMap.put(zhsname, 1);
        sfzyqzxMap.put(zysname, -1);
        insRulMap.put(Instruction.SFZYQZX.getValue(), sfzyqzxMap);

        //释放执行且占用
        Map<String, Integer> sfzxqzyMap = new HashMap<>();
        sfzxqzyMap.put(zhsname, -1);
        sfzxqzyMap.put(zysname, 1);
        insRulMap.put(Instruction.SFZXQZY.getValue(), sfzxqzyMap);

        //仅项目执行	        XMZX
        Map<String, Integer> xmzxMap = new HashMap<>();
        xmzxMap.put(zhsname, 1);
        xmzxMap.put(zysname, 0);
        insRulMap.put(Instruction.XMZX.getValue(), xmzxMap);

        //仅项目释放执行	        XMSFZX
        Map<String, Integer> xmsfzxMap = new HashMap<>();
        xmsfzxMap.put(zhsname, -1);
        xmsfzxMap.put(zysname, 0);
        insRulMap.put(Instruction.XMSFZX.getValue(), xmsfzxMap);

        //仅项目占用	        XMZY
        Map<String, Integer> xmzyMap = new HashMap<>();
        xmzyMap.put(zhsname, 0);
        xmzyMap.put(zysname, 1);
        insRulMap.put(Instruction.XMZY.getValue(), xmzyMap);

        //仅项目释放占用	        XMSFZY
        Map<String, Integer> xmsfzYMap = new HashMap<>();
        xmsfzYMap.put(zhsname, 0);
        xmsfzYMap.put(zysname, -1);
        insRulMap.put(Instruction.XMSFZY.getValue(), xmsfzYMap);

        //仅项目释放占用且执行	        XMSFZYQZX
        Map<String, Integer> xmsfzyqzxMap = new HashMap<>();
        xmsfzyqzxMap.put(zhsname, 1);
        xmsfzyqzxMap.put(zysname, -1);
        insRulMap.put(Instruction.XMSFZYQZX.getValue(), xmsfzyqzxMap);

        //仅项目释放执行且占用	        XMSFZXQZY
        Map<String, Integer> xmsfzxqzyMap = new HashMap<>();
        xmsfzxqzyMap.put(zhsname, -1);
        xmsfzxqzyMap.put(zysname, 1);
        insRulMap.put(Instruction.XMSFZXQZY.getValue(), xmsfzxqzyMap);

        try {
            //指令
            String instruction = Util.null2String(params.getOrDefault("instruction", ""));
            if (!insRulMap.containsKey(instruction)) {
                resMap.put("status", 0);
                VerifyMessage.SUCCESS.fromMap(resMap);
                return resMap;
            }

            Map<String, Integer> instructionMap = insRulMap.get(instruction);

            //预算项目
            String budgetItem = Util.null2String(params.getOrDefault("budgetItem", ""));
            //预算科目
            String budgetAccount = Util.null2String(params.getOrDefault("budgetAccount", ""));
            //执行单位
            String exeUnit = Util.null2String(params.getOrDefault("exeUnit", ""));
            //金额
            double amount = Util.getDoubleValue(
                    params.getOrDefault("amount", "0.000000").toString(), 0.000000);

            //查询项目底表需要跟新的明细
            String selectsql = "select t2.id id, t.yssx yssx from " + ysxmdbName + " t " +
                    " inner join " + ysxmdbName + "_dt2 t2 on t.id = t2.mainid " +
                    " where t.xmbm = ? and t2.yskm = ? and t.zz = ? ";

            boolean sqlFlag = rstrans.executeQuery(selectsql, budgetItem, budgetAccount, exeUnit);
            logger.info("logId:" + logId + "预算项目底表全周期明细金额字段写入查询执行结构，flag" + sqlFlag + ",sql:" + selectsql + "==>budgetItem:" + budgetItem
                    + ",budgetAccount:" + budgetAccount + ",exeUnit:" + exeUnit);

            if (!sqlFlag || rstrans.getCounts() != 1) {
                resMap.put("status", -1);
                VerifyMessage.YWYZ_ERR.setErrorMessage("预算项目底表全周期明细未成功匹配到数据！").fromMap(resMap);
                rstrans.rollback();
                return resMap;
            }
            rstrans.next();
            //项目明细_dt2id
            String xmId = rstrans.getString("id");

            //预算事项id
            String yssxid = rstrans.getString("yssx");

            selectsql = "select t2.id id from " + yssxdbName + " t " +
                    " inner join " + yssxdbName + "_dt2 t2 on t.id = t2.mainid " +
                    " where t.sxbm = ? and t2.yskm = ? ";

            sqlFlag = rstrans.executeQuery(selectsql, yssxid, budgetAccount);
            logger.info("logId:" + logId + "预算项目底表全周期明细金额字段写入查询执行结构，flag" + sqlFlag + ",sql:" + selectsql + "==>id:" + yssxid
                    + ",budgetAccount:" + budgetAccount);

            if (!sqlFlag || rstrans.getCounts() != 1) {
                resMap.put("status", -1);
                VerifyMessage.YWYZ_ERR.setErrorMessage("预算项目底表全周期明细未成功匹配到数据！").fromMap(resMap);
                rstrans.rollback();
                return resMap;
            }
            rstrans.next();
            //事项明细dt2_id
            String sxId = rstrans.getString("id");


            String sql = "update " + ysxmdbName + "_dt2 set ";

            //执行单据类型
            String exeDocType = Util.null2String(params.getOrDefault("exeDocType", ""));
            //被占用单据号
            String occDocNo = Util.null2String(params.getOrDefault("occDocNo", ""));


            List<Object> upDataList = new ArrayList<>();
            for (String key : instructionMap.keySet()) {

                Integer val = instructionMap.get(key);

                upDataList.add(val * amount);
                sql = sql + (key + " = (case when " + key + " is null then 0 else " + key + " end) + ?,");

            }
            sql = sql.substring(0, sql.length() - 1);
            sql = sql + " where id = ?";
            upDataList.add(xmId);


            sqlFlag = rstrans.executeUpdate(sql, upDataList);
            logger.info("logId:" + logId + "预算项目目表全周期明细金额字段写入结果，flag" + sqlFlag + "," +
                    "sql:" + sql + "==>" + upDataList + ":" + upDataList);
            if (!sqlFlag) {
                rstrans.rollback();
                resMap.put("status", -2);
                VerifyMessage.UPDATE_ERR.setErrorMessage("预算项目底表全周期明细更新失败！").fromMap(resMap);
                return resMap;
            }

            sql = "update " + yssxdbName + "_dt2 set ";

            upDataList = new ArrayList<>();
            for (String key : instructionMap.keySet()) {
                Integer val = instructionMap.get(key);

                upDataList.add(val * amount);
                sql = sql + (key + " = (case when " + key + " is null then 0 else " + key + " end) + ?,");

            }
            sql = sql.substring(0, sql.length() - 1);
            sql = sql + " where id = ?";
            upDataList.add(sxId);
            sqlFlag = rstrans.executeUpdate(sql, upDataList);
            logger.info("logId:" + logId + "预算事项目表全周期明细金额字段写入结果，flag" + sqlFlag + "," +
                    "sql:" + sql + "==>" + upDataList + ":" + upDataList);
            if (!sqlFlag) {
                rstrans.rollback();
                resMap.put("status", -2);
                VerifyMessage.UPDATE_ERR.setErrorMessage("预算事项底表全周期明细更新失败！").fromMap(resMap);
                return resMap;
            } else {
                resMap.put("status", 0);
                VerifyMessage.SUCCESS.fromMap(resMap);
                return resMap;
            }

        } catch (Exception e) {
            rstrans.rollback();
            logger.error("logId:" + logId + "预算项目、事项底表全周期明细更新异常！，err:" + e.getMessage(), e);
            resMap.put("status", -2);
            VerifyMessage.UPDATE_ERR.setErrorMessage("预算项目、事项底表全周期明细更新异常！").fromMap(resMap);
            return resMap;
        }
    }

    /**
     * @param:
     * @return: java.util.Map<java.lang.String, java.lang.Object>
     * @description: 金额字段写入占用明细表
     */
    public Map<String, Object> writeInZybmx(List<String> modeids) {

        Map<String, Object> resMap = new HashMap<>();

        //占用期初金额 字段名
        String zycqjesname = "zyqcje ";
        //占用调整金额 字段名
        String zytzjename = "zydzje";
        //执行金额
        String zxjename = "zhje";

//        预算指令	                     占用期初金额	                    占用调整金额                      执行金额
//        占用		        ZY           查不到数据则插入【传入金额】到此字段	查到数据，则累加【传入金额】
//        释放占用		    SFZY                                        累减【传入金额】
//        释放占用且执行	    SFZYQZX                                     累减【传入金额】	                累加【传入金额】
//        释放执行且占用	    SFZXQZY      查不到数据则插入【传入金额】到此字段	查到数据，则累加【传入金额】 	        累减【传入金额】

//        仅项目占用		    XMZY         查不到数据则插入【传入金额】到此字段	查到数据，则累加【传入金额】
//        仅项目释放占用		XMSFZY                                      累减【传入金额】
//        仅项目释放占用且执行	XMSFZYQZX                                   累减【传入金额】	                累加【传入金额】
//        仅项目释放执行且占用	XMSFZXQZY   查不到数据则插入【传入金额】到此字段	查到数据，则累加【传入金额】      	累减【传入金额】
        Map<String, Map<String, Integer>> insRulMap = new HashMap<>();
        //执行
        Map<String, Integer> zxMap = new HashMap<>();
        zxMap.put(zycqjesname, 1);
        zxMap.put(zytzjename, 1);
        zxMap.put(zxjename, 0);
        zxMap.put("insFlag", 1);
        insRulMap.put(Instruction.ZY.getValue(), zxMap);
        insRulMap.put(Instruction.XMZY.getValue(), zxMap);

        //释放占用
        Map<String, Integer> sfzyMap = new HashMap<>();
        sfzyMap.put(zycqjesname, 0);
        sfzyMap.put(zytzjename, -1);
        sfzyMap.put(zxjename, 0);
        zxMap.put("insFlag", 0);
        insRulMap.put(Instruction.SFZY.getValue(), sfzyMap);
        insRulMap.put(Instruction.XMSFZY.getValue(), sfzyMap);

        //释放占用且执行  SFZYQZX
        Map<String, Integer> sfzyqzxMap = new HashMap<>();
        sfzyqzxMap.put(zycqjesname, 0);
        sfzyqzxMap.put(zytzjename, -1);
        sfzyqzxMap.put(zxjename, 1);
        zxMap.put("insFlag", 0);
        insRulMap.put(Instruction.SFZYQZX.getValue(), sfzyqzxMap);
        insRulMap.put(Instruction.XMSFZYQZX.getValue(), sfzyqzxMap);

        //释放执行且占用	    SFZXQZY
        Map<String, Integer> sfzxqzyMap = new HashMap<>();
        sfzxqzyMap.put(zycqjesname, 1);
        sfzxqzyMap.put(zytzjename, 1);
        sfzxqzyMap.put(zxjename, -1);
        zxMap.put("insFlag", 1);
        insRulMap.put(Instruction.SFZXQZY.getValue(), sfzxqzyMap);
        insRulMap.put(Instruction.XMSFZXQZY.getValue(), sfzxqzyMap);


        try {
            //指令
            String instruction = Util.null2String(params.getOrDefault("instruction", ""));
            if (!insRulMap.containsKey(instruction)) {
                resMap.put("status", 0);
                VerifyMessage.SUCCESS.fromMap(resMap);
                return resMap;
            }

            Map<String, Integer> instructionMap = insRulMap.get(instruction);


            //预算项目
            String budgetItem = Util.null2String(params.getOrDefault("budgetItem", ""));
            //预算科目
            String budgetAccount = Util.null2String(params.getOrDefault("budgetAccount", ""));
            //执行单位
            String exeUnit = Util.null2String(params.getOrDefault("exeUnit", ""));
            //金额
            double amount = Util.getDoubleValue(
                    params.getOrDefault("amount", "0.000000").toString(), 0.000000);

            //被占用单据号
            String occDocNo = Util.null2String(params.getOrDefault("occDocNo", ""));
            //执行单据号
            String exeDocNo = Util.null2String(params.getOrDefault("exeDocNo", ""));
            //执行单据类型
            String exeDocType = Util.null2String(params.getOrDefault("exeDocType", ""));
            //单据号
            String djh = occDocNo;
            if (Instruction.ZX.getValue().equals(instruction) || Instruction.XMZX.getValue().equals(instruction)) {
                djh = exeDocNo;
            }
            if ("营销事项申请流程".equals(exeDocType)) {
                if (exeDocNo.isEmpty()) {
                    instructionMap = insRulMap.get(Instruction.ZY.getValue());
                }
            }
            //报账人
            String claimant = Util.null2String(params.getOrDefault("claimant", ""));
            //预算年度
            String budgetPeriod = Util.null2String(params.getOrDefault("budgetPeriod", ""));
            //预算事项
            String event = Util.null2String(params.getOrDefault("event", ""));
            //执行日期
            String executionDate = Util.null2String(params.getOrDefault("executionDate", ""));


            //查询占用主表数据
            String selectSql = "select id from " + yszybName + " where djbh = ?";
            boolean sqlFlag = rstrans.executeQuery(selectSql, djh);
            logger.info("logId:" + logId + "预算占用主表查询结果，flag" + sqlFlag + "," +
                    "sql:" + selectSql + "==>(" + djh + ")");
            //占用表id
            String zybMainId = "";
            //是否新增数据
            Integer insFlag = 0;
            if (rstrans.next()) {
                zybMainId = Util.null2String(rstrans.getString("id"));
            } else {
                insFlag = instructionMap.get("insFlag");
                if (insFlag == 0) {
                    rstrans.rollback();
                    resMap.put("status", -2);
                    VerifyMessage.UPDATE_ERR.setErrorMessage("占用底表未匹配到数据！").fromMap(resMap);
                    return resMap;
                }
            }

            //占用期出金额
            double zyqcje = instructionMap.get(zycqjesname) * amount;
            //占用调整金额
            double zytzje = 0.000000;
            //执行金额
            double zxje = instructionMap.get(zxjename) * amount;


            if (insFlag == 1) {
                //查询表单对应modeid
                String sql = "select a.id id from modeinfo a " +
                        "left join workflow_bill b on a.formid=b.id where b.tablename = ?";
                rstrans.executeQuery(sql, yszybName);
                rstrans.next();

                String uuid = UUID.randomUUID().toString();
                String modeid = Util.null2String(rstrans.getString("id"));
                String dateString = TimeUtil.getCurrentDateString();
                String timeString = TimeUtil.getOnlyCurrentTimeString();

                //操作人账号对应人力资源id
                //String claimant_id = Util.null2String(params.getOrDefault("claimant_id", ""));
                User user = (User) otherParams.get("user");
                int uid = user.getUID();

                //状态
                String zt = "0";

                String insMainSql = "insert into " + yszybName +
                        "(modeuuid,modedatacreater,modedatacreatedate,modedatacreatetime,formmodeid,zz,dyysbzr,djbh,zt,ysnd) " +
                        "values(?,?,?,?,?,?,?,?,?,?)";

                sqlFlag = rstrans.executeUpdate(insMainSql, uuid, uid, dateString, timeString, modeid,
                        exeUnit, claimant, djh, zt, budgetPeriod);
                logger.info("logId:" + logId + "预算占用表写入结果，flag" + sqlFlag + "," +
                        "sql:" + insMainSql + "==>modeuuid:" + uuid + ",modedatacreater:" + uid + ",modedatacreatedate:" + dateString
                        + ",modedatacreatetime:" + timeString + ",formmodeid:" + modeid + ",zz:" + exeUnit + ",dyysbzr:" + claimant
                        + ",djbh:" + djh + ",zt:" + zt + ",ysnd:" + budgetPeriod);


                rstrans.executeSql("select id from " + yszybName + " where modeuuid='" + uuid + "'");
                rstrans.next();

                zybMainId = Util.null2String(rstrans.getString("id"));

                String insDetaillsql = "insert into " + yszybName + "_dt1 " +
                        "(mainid, ysnd, ysxm, yskm, yssx, zhdw, dh, rq, zyqcje, zydzje, zyje, zhje, zyye, zhdjlx) " +
                        "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                String zyje = "0.000000";
                String zyye = "0.000000";
                String zhdjlx = "0";
                sqlFlag = rstrans.executeUpdate(insDetaillsql, zybMainId, budgetPeriod, budgetItem, budgetAccount, event,
                        exeUnit, djh, executionDate, zyqcje, zytzje, zyje, zxje, zyye, zhdjlx);
                logger.info("logId:" + logId + "预算占用明细表写入结果，flag" + sqlFlag + "," +
                        "sql:" + insDetaillsql + "==>(" + zybMainId + "," + budgetPeriod + "," + budgetItem + ","
                        + budgetAccount + "," + event + "," + exeUnit + "," + djh + "," + executionDate + "," + zyqcje + "," + zytzje + ","
                        + zyje + "," + zxje + "," + zyye + "," + zhdjlx + ")");
                modeids.add(zybMainId);

            } else {
                //查询占用明细主表数据
                double zyyeYx = 0.000000;
                if ("营销预付款退回流程".equals(exeDocType)) {
                    selectSql = "select a.id,a.zyye from "+yszybName+"_dt1 a left join workflow_requestbase b  on  b.requestid = a.dh where  b. currentnodetype = 3 AND a.ysxm = ? AND a.zhdjlx = ?";
                    sqlFlag = rstrans.executeQuery(selectSql, occDocNo, exeDocType);
                    rstrans.next();
                    zyyeYx = Util.getDoubleValue(Util.null2String(rstrans.getString("zyye")), 0.000000);
                    selectSql = "select a.id,a.zydzje from " + yszybName + "_dt1 a left join workflow_requestbase b  on  b.requestid = a.dh where  b. currentnodetype = 3 AND a.ysxm = ? AND ( a.zhdjlx = ? OR a.zhdjlx = ? )";
                    sqlFlag = rstrans.executeQuery(selectSql, occDocNo, "营销预付款流程", "市场费用支出报账流程-预付");
                    while (rstrans.next()) {
                        String id = Util.null2String(rstrans.getString("id"));
                        double zydzje = Util.getDoubleValue(Util.null2String(rstrans.getString("zydzje")), 0.000000);
                        String upDetailsql ="";
                        if (zyyeYx > zydzje) {
                            zyyeYx = zyyeYx - zydzje;
                            upDetailsql = "update " + yszybName + "_dt1 set zydzje = (case when zydzje is null then 0 else 0 end)  where id = ? ";
                            sqlFlag = rstrans.executeQuery(upDetailsql, id);
                        } else {
                            upDetailsql = "update " + yszybName + "_dt1 set zydzje = (case when zydzje is null then 0 else zydzje end) + ?  where id = ? ";
                            sqlFlag = rstrans.executeQuery(upDetailsql, "-" + zyyeYx, id);
                        }
                        logger.info("logId:" + logId + "预算占用明细表查询结果...营销预付款退回流程:，flag" + sqlFlag + "," +
                                "sql:" + upDetailsql + "==>(" + zybMainId + ", -" + zyyeYx + "," + id + ")");
                    }
                } else {
                    if ("营销预付款流程".equals(exeDocType) || "市场费用支出报账流程-预付".equals(exeDocType)) {
                        //occDocNo;
                        selectSql = "select id from " + yszybName + "_dt1 where ysxm = ? and  zhdjlx = ? ";
                        sqlFlag = rstrans.executeQuery(selectSql, occDocNo, exeDocType);

                    } else {
                        selectSql = "select id from " + yszybName + "_dt1 where mainid = ? and ysnd =? and ysxm = ? and yskm = ? ";
                        sqlFlag = rstrans.executeQuery(selectSql, zybMainId, budgetPeriod, budgetItem, budgetAccount);
                    }

                    logger.info("logId:" + logId + "预算占用明细表查询结果，flag" + sqlFlag + "," +
                            "sql:" + selectSql + "==>(" + zybMainId + "," + budgetPeriod + "," + budgetItem + "," + budgetAccount + ")");
                    if (rstrans.next()) {
                        String zybDetailId = "";
                        String upDetailsql = "update " + yszybName + "_dt1 set zydzje = (case when zydzje is null then 0 else zydzje end) + ? ,  " +
                                "zhje = (case when zhje is null then 0 else zhje end) + ? ";
                        if ("营销事项申请调整流程".equals(exeDocType) || "核销报账流程".equals(exeDocType) || "核算入账".equals(exeDocType)) {
                            zybDetailId = occDocNo;
                            upDetailsql = upDetailsql + " where dh = ? ";
                        } else {
                            zybDetailId = Util.null2String(rstrans.getString("id"));
                            upDetailsql = upDetailsql + " where id = ? ";
                        }


                        //占用调整金额
                        zytzje = instructionMap.get(zytzjename) * amount;

                        sqlFlag = rstrans.executeUpdate(upDetailsql, zytzje, zxje, zybDetailId);
                        logger.info("logId:" + logId + "预算占用明细表更新结果，flag" + sqlFlag + "," +
                                "sql:" + upDetailsql + "==>(" + zytzje + "," + zxje + "," + zybDetailId + ")");

                    } else {
                        insFlag = instructionMap.get("insFlag");
                        if (insFlag == 0) {
                            rstrans.rollback();
                            resMap.put("status", -2);
                            VerifyMessage.UPDATE_ERR.setErrorMessage("占用底表明细表未匹配到数据！").fromMap(resMap);
                            return resMap;
                        } else {
                            String insDetaillsql = "insert into " + yszybName + "_dt1 " +
                                    "(mainid, ysnd, ysxm, yskm, yssx, zhdw, dh, rq, zyqcje, zydzje, zyje, zhje, zyye, zhdjlx) " +
                                    "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                            String zyje = "0.000000";
                            String zyye = "0.000000";
                            String zhdjlx = "0";
                            sqlFlag = rstrans.executeUpdate(insDetaillsql, zybMainId, budgetPeriod, budgetItem, budgetAccount, event,
                                    exeUnit, djh, executionDate, zyqcje, zytzje, zyje, zxje, zyye, zhdjlx);
                            logger.info("logId:" + logId + "预算占用明细表写入结果2，flag" + sqlFlag + "," +
                                    "sql:" + insDetaillsql + "==>(" + zybMainId + "," + budgetPeriod + "," + budgetItem + ","
                                    + budgetAccount + "," + event + "," + exeUnit + "," + djh + "," + executionDate + "," + zyqcje + ","
                                    + zytzje + "," + zyje + "," + zxje + "," + zyye + "," + zhdjlx + ")");
                        }
                    }
                }
            }

        } catch (Exception e) {
            rstrans.rollback();
            resMap.put("status", -2);
            logger.error("logId:" + logId + "预算占用底表更新异常！，err:" + e.getMessage(), e);
            VerifyMessage.UPDATE_ERR.setErrorMessage("预算占用底表更新异常！").fromMap(resMap);
            return resMap;
        }

        resMap.put("status", 0);
        VerifyMessage.SUCCESS.fromMap(resMap);
        return resMap;
    }


    /**
     * @param:
     * @return: java.util.Map<java.lang.String, java.lang.Object>
     * @description: 添加日志
     */
    public static Map<String, Object> addInstructionLog(Map<String, Object> params, Map<String, Object> resMap, RecordSet rs) {

        try {
            //需要插入的数据
            List<String> keyList = new ArrayList<>();
            List<String> valList = new ArrayList<>();

//        budgetItem		预算项目
            String budgetItem = Util.null2String(params.getOrDefault("budgetItem", ""));
            keyList.add("ysxm");
            valList.add(budgetItem);
//        budgetAccount		预算科目
            String budgetAccount = Util.null2String(params.getOrDefault("budgetAccount", ""));
            keyList.add("yskm");
            valList.add(budgetAccount);
//        exeUnit		执行单位
            String exeUnit = Util.null2String(params.getOrDefault("exeUnit", ""));
            keyList.add("zz");
            valList.add(exeUnit);
//        budgetPeriod		预算期间（年）
            String budgetPeriod = Util.null2String(params.getOrDefault("budgetPeriod", ""));
            keyList.add("ysnd");
            valList.add(budgetPeriod);
//        amount	金额
            String amount = Util.null2String(params.getOrDefault("amount", ""));
            keyList.add("je");
            valList.add(amount);
//        instruction		指令
            String instruction = Util.null2String(params.getOrDefault("instruction", ""));
            keyList.add("zl");
            valList.add(instruction);
//        occDocNo		被占用单据号
            String occDocNo = Util.null2String(params.getOrDefault("occDocNo", ""));
            keyList.add("bzydjh");
            valList.add(occDocNo);
//        exeDocNo		执行单据号
            String exeDocNo = Util.null2String(params.getOrDefault("exeDocNo", ""));
            keyList.add("zhdjh");
            valList.add(exeDocNo);
//        budgetPostingPeriod		预算控制期
            String budgetPostingPeriod = Util.null2String(params.getOrDefault("budgetPostingPeriod", ""));
            keyList.add("ysrzqj");
            valList.add(budgetPostingPeriod);
//        executionDate		执行日期
            String executionDate = Util.null2String(params.getOrDefault("executionDate", ""));
            keyList.add("zhrq");
            valList.add(executionDate);
//        exeDocType		执行单据类型
            String exeDocType = Util.null2String(params.getOrDefault("exeDocType", ""));
            keyList.add("zhdjlx");
            valList.add(exeDocType);
//        claimant		报账人
            String claimant = Util.null2String(params.getOrDefault("claimant", ""));
            keyList.add("sqr");
            valList.add(claimant);
//        sourceSystem		来源系统
            String sourceSystem = Util.null2String(params.getOrDefault("sourceSystem", ""));
            keyList.add("lyxt");
            valList.add(sourceSystem);
//        remark		说明
            String remark = Util.null2String(params.getOrDefault("remark", ""));
            keyList.add("sm");
            valList.add(remark);
//        reimbursementDept		报账部门
            String reimbursementDept = Util.null2String(params.getOrDefault("reimbursementDept", ""));
            keyList.add("sqbm");
            valList.add(reimbursementDept);
//        reimbursementCompany		报账公司
            String reimbursementCompany = Util.null2String(params.getOrDefault("reimbursementCompany", ""));
            keyList.add("bzgs");
            valList.add(reimbursementCompany);
//        economicEvent		经济事项
            String economicEvent = Util.null2String(params.getOrDefault("economicEvent", ""));
            keyList.add("jjsx");
            valList.add(economicEvent);
//        event		事项
            String event = Util.null2String(params.getOrDefault("event", ""));
            keyList.add("yssx");
            valList.add(event);

            if (Instruction.JZX.equals(instruction)) {
                //是否执行成功
                String status = Util.null2String(resMap.getOrDefault("status", ""));
                keyList.add("sfzhcg");
                valList.add(status);

                //失败原因
                String errorMessage = Util.null2String(resMap.getOrDefault("errorMessage", ""));
                keyList.add("sbyy");
                valList.add(errorMessage);
            }


            //预算执行记录表
            String yszxjlbName = "uf_yszxjlb";

            StringJoiner keyJoiner = new StringJoiner(",");
            StringJoiner colJoiner = new StringJoiner(",");
            for (String key : keyList) {
                keyJoiner.add(key);
                colJoiner.add("?");
            }

            String sql = "insert into " + yszxjlbName + " (" + keyJoiner + ") values(" + colJoiner + ")";
            rs.executeUpdate(sql, valList);
        } catch (Exception e) {
            e.printStackTrace();
            resMap.put("status", -2);
            VerifyMessage.UPDATE_ERR.setErrorMessage("预算执行指令表更新失败！").fromMap(resMap);
            return resMap;
        }

        resMap.put("status", 0);
        VerifyMessage.SUCCESS.fromMap(resMap);
        return resMap;

    }

    /**
     * @param:
     * @return: java.util.Map<java.lang.String, java.lang.Object>
     * @description: 获取电商平台控制接口 查询年度剩余可用预算百分比
     */
    public Map<String, Object> getRemainBudgetPer() {
        Map<String, Object> resMap = new HashMap<>();
        RecordSet rs = new RecordSet();
        //预算项目
        String budgetItem = Util.null2String(params.getOrDefault("budgetItem", ""));
        //预算科目
        String budgetAccount = Util.null2String(params.getOrDefault("budgetAccount", ""));
        //执行单位
        String exeUnit = Util.null2String(params.getOrDefault("exeUnit", ""));
        //预算期间（年）
        String budgetPeriod = Util.null2String(params.getOrDefault("budgetPeriod", ""));

        //查询项目底表需要跟新的明细
        String selectsql = "select t1.ndys,t1.ysye from " + ysxmdbName + " t " +
                " inner join " + ysxmdbName + "_dt1 t1 on t.id = t1.mainid " +
                " where t.xmbm = ? and t1.yskm = ? and t.zz = ? and t1.ysnd = ? ";

        boolean sqlFlag = rs.executeQuery(selectsql, budgetItem, budgetAccount, exeUnit, budgetPeriod);
        logger.info("logId:" + logId + "查询年度剩余可用预算，flag" + sqlFlag + ",sql:" + selectsql + "==>budgetItem:" + budgetItem
                + ",budgetAccount:" + budgetAccount + ",exeUnit:" + exeUnit + ",budgetPeriod:" + budgetPeriod);

        if (!sqlFlag || rs.getCounts() != 1) {
            resMap.put("status", -1);
            VerifyMessage.YWYZ_ERR.setErrorMessage("查询年度剩余可用预算未成功匹配到数据！").fromMap(resMap);
            return resMap;
        }

        rs.next();

        //年度预算
        String ndys = Util.getDoubleValue(rs.getString("ndys"), 0) == 0 ? "1"
                : Util.getDoubleValue(rs.getString("ndys"), 0) + "";
        BigDecimal ndysDecimal = new BigDecimal(ndys);
        //预算余额
        String ysye = Util.getDoubleValue(rs.getString("ysye"), 0) + "";
        BigDecimal ysyeDecimal = new BigDecimal(ysye);

        BigDecimal result = ysyeDecimal.divide(ndysDecimal, 4, BigDecimal.ROUND_HALF_UP)
                .multiply(new BigDecimal(100));

        DecimalFormat decimalFormat = new DecimalFormat("0.00");

        String percentage = decimalFormat.format(result) + "%";

        resMap.put("budgetAmountAll", decimalFormat.format(ndysDecimal));
        resMap.put("budgetBalance", decimalFormat.format(ysyeDecimal));
        resMap.put("percentage", percentage);
        resMap.put("status", 0);

        return resMap;
    }


    /**
     * @param: selSql
    upTablename
    instructionMap
    resMap
     * @return: java.util.Map<java.lang.String, java.lang.Object>
     * @description: 金额字段写入数据库
     */
    /*
    public Map<String, Object> writeInAmount(String selSql, List<String> selSqlList, String upTablename,
                                             Map<String, Integer> instructionMap, Map<String, Object> resMap) {

        try {

            //金额
            double amount = Util.getDoubleValue(
                    params.getOrDefault("amount", "0.000000").toString(), 0.000000);

            boolean sqlFlag = rstrans.executeQuery(selSql, selSqlList);
            logger.info("预算事项底表金额字段写入查询执行结构，flag"+sqlFlag+",sql:"+selSql+"==>selSqlList:"+selSqlList);

            if(!sqlFlag || rstrans.getCounts() != 1) {
                resMap.put("status", -1);
                VerifyMessage.YWYZ_ERR.setErrorMessage("预算事项底表未成功匹配到数据！").fromMap(resMap);
                return resMap;
            }
            rstrans.next();
            String id = rstrans.getString("id");

            String sql = "update "+upTablename+" set ";

            List<Object> upDataList = new ArrayList<>();
            for(String key : instructionMap.keySet()) {
                Integer val = instructionMap.get(key);

                upDataList.add(val * amount);
                sql = sql + ( key+" = "+key+" + ?,");
            }
            sql = sql.substring(0, sql.length()-1);
            sql = sql+" where id = ?";
            upDataList.add(id);

            sqlFlag = rstrans.executeUpdate(sql, upDataList);
            logger.info("预算事项底表金额字段写入结果，flag"+sqlFlag+"," +
                    "sql:"+sql+"==>"+upDataList+":"+upDataList);
            if(!sqlFlag) {
                rstrans.rollback();
                resMap.put("status", -2);
                VerifyMessage.UPDATE_ERR.setErrorMessage("预算事项底表更新失败！").fromMap(resMap);
                return resMap;
            }else {
                resMap.put("status", 0);
                VerifyMessage.SUCCESS.fromMap(resMap);
                return resMap;
            }

        }catch (Exception e) {
            rstrans.rollback();
            resMap.put("status", -2);
            VerifyMessage.UPDATE_ERR.setErrorMessage("预算事项底表更新异常！").fromMap(resMap);
            return resMap;
        }
    }
    */

}
